package com.bigdata.utils;/**
 * Created by Administrator on 2019/7/9 0009.
 */

import com.bigdata.model.User;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Administrator
 * @description
 * @date 2019/7/9 0009
 */
public class StringUtil {
    public static List<String> splitList(String ids) {
        List<String> lids = new ArrayList<String>();
        if (isNullorEmpty(ids)) {
            String[] sps = ids.split(",");
            for (String rp : sps) {
                if (StringUtil.isNullorEmpty(rp)) {
                    lids.add(rp);
                }
            }
        }
        return lids;
    }

    public static boolean isNullorEmpty(String data) {
        if (data != null && data.length() > 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean inStringIgnoreCase(String str, String... strs) {
        if (str != null && strs != null) {
            for (String s : strs) {
                if (str.equalsIgnoreCase(s.trim())) {
                    return true;
                }
            }
        }
        return false;
    }

    public static String urlEl(User user, String url) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("${username}", user.getUserName());
        map.put("${password}", user.getPassword());
        String regex = "\\$\\{[^\\}]+\\}";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(url);
        while (m.find()) {
            String gp = m.group();
            String k = map.get(gp);
            if (k != null) {
                url = url.replace(gp, k);
            }
        }
        return url;
    }

    public static byte[] getBytes(String obj) {
        return obj.getBytes();
    }
}
